package com.example.meitao.task;

import android.os.AsyncTask;
import android.util.Log;

import com.example.meitao.bean.Discount;
import com.example.meitao.tools.HttpUtils;
import com.google.gson.Gson;

/**
 * Created by 星星 on 2016/8/30.
 */
public abstract class DiscountNetTask extends AsyncTask<String ,Void,Discount> {
    private static  final  String  TAG = Discount.class.getSimpleName();
    public abstract  void onCallBack(Discount result);
    @Override
    protected Discount doInBackground(String... params) {
        Log.d(TAG, "doInBackground: thead ==" +Thread.currentThread().getName());
        final byte[] data = HttpUtils.getDataBytes(params[0]);
        if (data!=null&&data.length>0){
            Gson gson = new Gson();
            return  gson.fromJson(new String(data),Discount.class);
        }
        return null;
    }

    @Override
    protected void onPostExecute(Discount groom) {
        Log.d(TAG, "doInBackground: thead ==" +Thread.currentThread().getName());
        if (groom!=null){
            onCallBack(groom);
        }

    }
}
